package 字节;

import java.util.*;

public class Main_1016_1 {
    public static void main(String[] args) {
        Scanner cin=new Scanner(System.in);
        int n=cin.nextInt(),max=cin.nextInt();
        //统计每个数字出现的次数
        Map<Integer,Integer> count=new HashMap<>();
        List<Integer> can2=new ArrayList<>();
        List<Integer> can3=new ArrayList<>();
        for (int i = 0; i < n; i++) {
            int num=cin.nextInt();
            count.put(num,count.getOrDefault(num,0)+1);
            if (!can2.contains(num)&&count.get(num)>=2){
                can2.add(num);
            }
            if (!can3.contains(num)&&count.get(num)>=3){
                can3.add(num);
            }
        }
        if (can2.size()==0||can3.size()==0){
            System.out.println("0 0");
            return;
        }
        //可以在出现次数大于等于2的数字中选择b，然后再在出现次数大于等于3的数字中选择不同于b的a
        Collections.sort(can2);
        Collections.sort(can3);
        int a=can3.size()-1,b=can2.size()-1;
        if ((can3.get(0)*3+can2.get(0)*2)>max){
            System.out.println("0 0");
            return;
        }
        if ((can3.get(a)*3+can2.get(b)*2)<=max){
            int anum=can3.get(a),bnum=can2.get(b);
            if (anum!=bnum){
                System.out.println(can3.get(a)+" "+can2.get(b));
                return;
            }
        }
        int sum=0;
        int ares=0,bres=0;
        for (a = can3.size()-1; a >=0 ; a-- ){
            for (b = can2.size()-1; b >=0 ; b--) {
                int anum=can3.get(a),bnum=can2.get(b);
                if (anum==bnum){
                    continue;
                }
                int cur=anum*3+bnum*2;
                if (cur<=max&&cur>sum){
                    ares=anum;
                    bres=bnum;
                    sum=cur;
                }
            }
        }
        if (ares==0){
            System.out.println("0 0");
        }else {
            System.out.println(ares+" "+bres);
        }
    }
}
